package exampleQuestions;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class GenerateAllSubsets {

	/**
	 * 
	 */
	public static void main(String[] args) {

		LinkedList<Set<Integer>> list = new LinkedList<Set<Integer>>();
		list.add(new HashSet<Integer>());
		
		Set<Integer> set = new HashSet<Integer>();
		set.add(5);
		set.add(15);
		set.add(25);
		
		list = generateSets(list, set);
		System.out.println(list.size());
		
		for(Set<Integer> s : list) {
			for(Integer i : s) {
				System.out.print(i + " ");
			}
			System.out.println();
		}
		
	}
	
	public static LinkedList<Set<Integer>> generateSets(LinkedList<Set<Integer>> list, Set<Integer> set) {

	    if (set.isEmpty()) {
	        return list;
	    } else {
	        Integer i = set.iterator().next();
	        set.remove(i);
	        LinkedList<Set<Integer>> newList = new LinkedList<Set<Integer>>(list);
	        for(Set<Integer> s : list) {
	            Set<Integer> tmpSet = new HashSet<Integer>(s);
	            tmpSet.add(i);
	            newList.add(tmpSet);
	        }
	        return generateSets(newList, set);
	    }
	}

}
